package com.lzh.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;

import java.math.BigDecimal;

/**
 * @author zhehen.lu
 * @date 2025/8/3 13:55
 */
public class EasyExcelBigDecimalPercentConverter implements Converter<BigDecimal> {
    public EasyExcelBigDecimalPercentConverter() {
    }

    @Override
    public Class supportJavaTypeKey() {
        return BigDecimal.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public WriteCellData<String> convertToExcelData(WriteConverterContext<BigDecimal> context) throws Exception {
        return new WriteCellData(((BigDecimal)context.getValue()).toString() + "%");
    }
}

